#include <iostream>
#include <vector>
#include <map>
using namespace std;

class Solution {
public:
    /**
     *
     * @param arr int整型vector the array
     * @return int整型
     */
    int maxLength(vector<int>& arr) {
        // write code here
        int size = arr.size();
        int left = 0, right = 0;
        int resmax = 1;
        int pos[100000] = {-1};

        for(right; right < size; right++){
            if(pos[arr[right]] >= left){
                left = pos[arr[right]] + 1;
                pos[arr[right]] = right;
                continue;
            }

            int tmp = right - left + 1;
            pos[arr[right]] = right;
            resmax = max(resmax, tmp);
        }

        return resmax;
    }
};
